using MultiplayerServerConnectionHandlers;
using MultiplayerServerDiscoveryHandlers;
using UnityEngine;

public class ServerRolePicker : UILayer
{
	public UISprite gameButton;

	public Vector3 testEulerInitDir;

	public Vector3 testEulerFinalDir;

	public GameObject selfLayer;

	public GameObject gyroLayer;

	private void OnEnable()
	{
		UITools.ChangeSprite(gameButton, "button-plastic-green");
		Debug.Log("testRotOut: " + Quaternion.FromToRotation(testEulerInitDir, testEulerFinalDir).eulerAngles);
	}

	public void OnPickGameRole()
	{
		BehaviourSingleton<GGUDPNetworkServer>.instance.EndServer();
		BehaviourSingleton<GGUDPNetworkServer>.instance.StartServer();
		BehaviourSingleton<GGUDPNetworkServer>.instance.AddHandler(new DiscoveryHandler());
		AcceptConnectionsHandler acceptConnectionsHandler = new AcceptConnectionsHandler();
		acceptConnectionsHandler.onNewConnection += delegate
		{
			ServerDetectionNavigation serverDetectionNavigation = NavigationManager.instance as ServerDetectionNavigation;
			if (serverDetectionNavigation != null)
			{
				serverDetectionNavigation.Push(serverDetectionNavigation.gameCallibrationLayer);
			}
		};
		BehaviourSingleton<GGUDPNetworkServer>.instance.AddHandler(acceptConnectionsHandler);
		UITools.ChangeSprite(gameButton, "button-plastic-red");
	}

	private new void Update()
	{
		if (isEntered && Input.GetKeyDown(KeyCode.Escape))
		{
			QuitScene();
		}
	}

	public void QuitScene()
	{
		BehaviourSingleton<ScreenNavigation>.instance.LoadMain(MenuParameters.MenuParams.ShowScreen.None);
	}
}
